<template>
	<view>
		
		<view v-if="azj.zjgsid">
			<view class="flex justify-between align-center padding-sm">
				<view>
					<text class="text-bold">业务员：</text>
					<text @tap="openEditName">{{azj.zjname ? azj.zjname : '未设定姓名'}}</text>
				</view>
				<view v-if="azj.zjname" class="flex justify-between align-center">
					<button size="mini" open-type="share">分享</button>
				</view>
				<view v-else class="flex justify-between align-center">
					<button size="mini" @tap="checkName">分享</button>
				</view>
			</view>
			<view class="flex justify-between align-center padding-sm">
				<text class="text-bold">佣金合计：</text>
				<text>￥{{acommission ? acommission.total / 100 : 0}}</text>
			</view>
			<view class="margin-top-sm">
				<view class="padding-xs w-25 inline-block">
					<view @tap="toMd" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-8"></text>
						</text>
						<text class="text-sm">门店数量</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{sCount}}</text>
					</view>
				</view>
				<view class="padding-xs w-25 inline-block">
					<view @tap="toYj" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-fenchengbili"></text>
						</text>
						<text class="text-sm">佣金明细</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{cCount}}</text>
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<view v-if="zjsq">
				<view class="padding">
					<text class="text-yellow">已经提交申请，等待中介公司确认。</text>
				</view>
			</view>
			<view v-else>
				<view class="padding">
					<text class="text-yellow">尚未明确中介公司，请先选择中介公司。</text>
				</view>
				<view>
					<view class="cu-form-group ">
						<view class="title">选择公司：</view>
						<view class="flex justify-end align-center">
							<zqs-select 
								@change="zjgsChange"
								value-key="zjgsid" label-key="zjgsnc" title="选择中介公司" 
								:list="zjgses" v-model="zj.zjgsid"></zqs-select>
						</view>
					</view>
					<view class="padding">
						<button @click="submitsq" class="cu-btn block bg-yellow lg">提交申请</button>
					</view>
				</view>
			</view>
		</view>
		
		<view style="background-color: rgba(255, 255, 255, 0.3); top: 0; left: 0;" v-if="showEdit"
			class="fixed vw-100 vh-100 flex justify-center align-center padding-xs">
			<view class="w-100 padding flex justify-between align-center shadow bg-white">
				<input class="" placeholder="请输入业务员姓名" v-model="azj.zjname" />
				<text @tap="updateZjname" class="bg-yellow padding-sm round">确认修改</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				showEdit: false,
				azj: this.store.state.zj,
				acommission: undefined,
				cCount: 0,
				sCount: 0,
				zjgses: [],
				keywords: "",
				zj: {
					zjid: this.store.state.zj.zjid,
					zjgsid: ""
				},
				zjsq: undefined,
			};
		},
		created: function() {
			
			if (this.azj.zjgsid) {
				this.loadZj();
			} else {
				this.loadZjsqitems();
			}

		},
		methods: {
			submitsq: function() {
				if (!this.zj.zjgsid) {
					this.message.warning("请先选择中介公司");
				}
				this.api("/zj/zjsq/info/post").send({
					sqitem: this.zj
				}).then(data => {
					this.zjsq = data.azjsqitem;
				});
			},
			zjgsChange: function(zjgs) {
				console.log(zjgs);
			},
			loadZjsqitems: function() {
				return this.api("/zj/zjsq/all/get").send({
					zjid: this.azj.zjid,
				}).then(data => {
					if (data.zjsqitems && data.zjsqitems.length > 0) {
						this.zjsq = data.zjsqitems[0];
					} else {
						this.loadZjgs();
					}
				});
			},
			loadZjgs: function(zjgsnc) {
				this.api("/zj/zjgs/all/get").send({
					zjgsnc,
				}).then(data => {
					this.zjgses = data.azjgses;
				});
			},
			loadZj: function() {
				this.api("/zj/info/get").send({
					zjid: this.azj.zjid
				}).then(data => {
					this.acommission = data.acommission;
					this.cCount = data.cCount;
					this.sCount = data.sCount;
				});
			},
			toMd: function() {
				uni.navigateTo({
					url: '/pages/czj/md/list?zjid='+this.azj.zjid
				});
			},
			toYj: function() {
				uni.navigateTo({
					url: '/pages/czj/yj/list?zjid='+this.azj.zjid
				});
			},
			checkName: function() {
				this.message.warning("请先设置业务员姓名");
			},
			openEditName: function() {
				this.showEdit = true;
			},
			updateZjname: function() {
				if (!this.azj.zjname) {
					this.message.info("中介名必须输入");
					return;
				}
				this.api("/zj/info/put").send({
					azj: this.azj
				}).then(data => {
					this.message.info("修改成功");
					this.showEdit = false;
					this.store.commit("submitZj", this.azj);
				});
			},
		},
	
	}
</script>

<style>
</style>